package com.project.internship.controller.base;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.internship.entity.Audit;
import com.project.internship.entity.resp.RespBean;
import com.project.internship.entity.resp.RespPageBean;
import com.project.internship.service.AuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/base/declare")
public class BaseDeclareController {

    @Autowired
    AuditService auditService;

    @PostMapping("/")
    public RespBean addDeclare(@RequestBody Audit audit){
        if(auditService.addDeclare(audit) == 1) {
            return RespBean.ok("添加成功");
        }
        return RespBean.error("添加失败");
    }

    @GetMapping("/")
    public RespPageBean getDeclare(@RequestParam(defaultValue = "1") Integer current,
                                   @RequestParam(defaultValue = "10") Integer size,
                                   String keyword) {
        Page<Audit> page = new Page<>(current,size);

        Long total = auditService.getDeclare(page,keyword).getTotal();
        List<Audit> data = auditService.getDeclare(page, keyword).getRecords();

        return new RespPageBean(total, data);
    }
}
